package com.example.zhaohang.employmentapp;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.example.zhaohang.adpter.NotPagerAdapter;
import com.example.zhaohang.fragment.PagerFragemnt;
import com.example.zhaohang.utils.AndroidWorkaround;
import com.example.zhaohang.weigit.NoScrollViewPager;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

public class EmailActivity extends AppCompatActivity {

    private final String[] title = {"通知", "活动"};
    private RelativeLayout mLeft;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private SlidingTabLayout  mTabLayout;
    private NoScrollViewPager mViewPager;
    private NotPagerAdapter   mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //        入侵式状态栏，只有5.0以后才能用，并且只能加到R.layout.xxx前面
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_email);

        mLeft = findViewById(R.id.left);
        mTabLayout = (SlidingTabLayout)findViewById(R.id.slidingtablayout);
        mViewPager = (NoScrollViewPager)findViewById(R.id.viewpager);

        //设置返回按钮
        View view = getLayoutInflater().inflate(R.layout.imageview, null);
        ImageView imageView = view.findViewById(R.id.icon);
        imageView.setImageResource(R.mipmap.back);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        mLeft.addView(view, params);
        mLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        for (int i = 1; i < title.length+1; i++) {
            mFragments.add(PagerFragemnt.getInstance(i+ ""));
        }

        //一句代码就可以控制是否滑动
        mViewPager.setNoScroll(true);
        mAdapter = new NotPagerAdapter(getSupportFragmentManager(), mFragments, title);
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setViewPager(mViewPager, title);





        //专为华为手机设置的底部被遮挡
        if (AndroidWorkaround.checkDeviceHasNavigationBar(this)) {
            AndroidWorkaround.assistActivity(findViewById(android.R.id.content));
        }


    }


}
